﻿Imports Microsoft.VisualBasic
Imports System.Linq

Namespace CodeMatrix.Business

    Public Enum UserPrivilege
        Staff
        Group
        Department
    End Enum

    Public NotInheritable Class UserContext

        Private Shared Function GetContext(Of T)(ByVal sessionName As String) As T

            If HttpContext.Current.Session(sessionName) Is Nothing Then
                Return Nothing
            Else
                Return CType(HttpContext.Current.Session(sessionName), T)
            End If

        End Function

        Private Shared Sub SetContext(ByVal sessionName As String, ByVal value As String)

            HttpContext.Current.Session(sessionName) = value

        End Sub

        Public Property Privilege() As UserPrivilege
            Get
                Return GetContext(Of UserPrivilege)("_Privilege")
            End Get
            Set(ByVal value As UserPrivilege)
                SetContext("_Privilege", value)
            End Set
        End Property

        Public Shared Function PadLeft(ByVal totalWidth As Integer, ByVal paddingString As String) As String
            Dim i As Integer = 0
            Dim rtn As String = ""
            For i = 0 To totalWidth - 1 Step 1
                rtn &= paddingString
            Next
            Return rtn
        End Function

    End Class
End Namespace